package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhPhonerecord;
import com.yinhe.system.service.IYhPhonerecordService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 电话记录Controller
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/system/phonerecord")
public class YhPhonerecordController extends BaseController
{
    @Autowired
    private IYhPhonerecordService yhPhonerecordService;

    /**
     * 查询电话记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhPhonerecord yhPhonerecord)
    {
        startPage();
        List<YhPhonerecord> list = yhPhonerecordService.selectYhPhonerecordList(yhPhonerecord);
        return getDataTable(list);
    }

    /**
     * 导出电话记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:export')")
    @Log(title = "电话记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhPhonerecord yhPhonerecord)
    {
        List<YhPhonerecord> list = yhPhonerecordService.selectYhPhonerecordList(yhPhonerecord);
        ExcelUtil<YhPhonerecord> util = new ExcelUtil<YhPhonerecord>(YhPhonerecord.class);
        util.exportExcel(response, list, "电话记录数据");
    }

    /**
     * 获取电话记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhPhonerecordService.selectYhPhonerecordById(id));
    }

    /**
     * 新增电话记录
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:add')")
    @Log(title = "电话记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhPhonerecord yhPhonerecord)
    {
        return toAjax(yhPhonerecordService.insertYhPhonerecord(yhPhonerecord));
    }

    /**
     * 修改电话记录
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:edit')")
    @Log(title = "电话记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhPhonerecord yhPhonerecord)
    {
        return toAjax(yhPhonerecordService.updateYhPhonerecord(yhPhonerecord));
    }

    /**
     * 删除电话记录
     */
    @PreAuthorize("@ss.hasPermi('system:phonerecord:remove')")
    @Log(title = "电话记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhPhonerecordService.deleteYhPhonerecordByIds(ids));
    }
}
